// var activtyApi = require('../activity-list/api/ActivtyListApiHandle.js');
// var chasefun_user = require('../../data/User.js');
// var catalogApi = require('/api/CatalogListApiHandle.js');
// var activityPassParams = require('../activity-list/ActivityPassParams.js');

Page({
  data: {
    keyword:"",
    list: [],
    hasMore: true,
    hasRefesh: false,
    listmodel: {
      list:[
        {
          id:"1"
        }
      ]
    },
    taglist_model: null,
    req_list_page: 1,
    show_catalog_menubar: false,//是否显示分类菜单内容bar
    animationData: {},
    tag1_menucontent_items: [
      {
        id:"0",
        name:"全部商区"
      },{
        id:"1",
        name:"观音桥"
      },{
        id:"2",
        name:"解放碑"
      }
    ], //分类菜单内容
    tag2_menucontent_items:  [
      {
        id:"0",
        name:"全部美食"
      },{
        id:"1",
        name:"火锅"
      },{
        id:"2",
        name:"江湖菜"
      },{
        id:"2",
        name:"自助餐"
      }
    ], //价格菜单内容
    tag3_menucontent_items:  [
      {
        id:"0",
        name:"智能排序"
      },{
        id:"1",
        name:"时间"
      },{
        id:"2",
        name:"价格"
      },{
        id:"2",
        name:"距离"
      }
    ], //排序菜单内容
    tag4_menucontent_items:  [
      {
        id:"0",
        name:"筛选"
      },{
        id:"1",
        name:"。。。"
      },{
        id:"2",
        name:"解放碑"
      }
    ], //排序菜单内容
    cata_menucontent_items: null, //页面引用的菜单内容,
    select_meun_citem_idx: "1", //分类列表菜单内容item选中状态 页面引用
    tag1_select_m_c_idx: 0, //分类列表'分类tag'菜单内容item选中状态
    tag2_select_m_c_idx: 0, //分类列表'价格'菜单内容item选中状态
    tag3_select_m_c_idx: 0, //分类列表'排序'菜单内容item选中状态
    tag4_select_m_c_idx: 0, //分类列表'排序'菜单内容item选中状态
    current_ca_menu_indi: null //当前分类列表内容指示 0分类 1价格 2排序 引用界面判断箭头指示方向


  },

  onLoad: function (options) {
    var this_page = this;

   this.setData({    
      keyword: options.key    
    }) 
  },
  //处理排序tags分类列表内容
  handle_result_tags_menu_list: function () {
    var result = activityPassParams.getList_tags();
    var cur_idx = result.idx;
    this.data.tag1_select_m_c_idx = cur_idx;
    console.log('temp tags is ' + result.data);
    var temp = [];
    for (var i = 0; i < result.data.length; i++) {
      var single = result.data[i];
      var item = {
        name: single.bqname,
        t_id: single.id,
        url: single.bqurl
      };
      temp.push(item);
    }
    this.data.tag_menucontent_items = temp;
    this.data.cata_menucontent_items = this.data.tag_menucontent_items;
    this.setData({
      cata_menucontent_items: this.data.cata_menucontent_items
    })

  },
  //处理排序菜单列表内容
  handle_result_order_menu_list: function () {
    var temp = [];
    var result = catalogApi.request_orderList();
    for (var i = 0; i < result.length; i++) {
      var single = result[i];
      var item = {
        name: single,
        t_id: null,
        url: null,
        type: single.type
      };
      temp.push(item);
    }
    this.data.order_menucontent_items = temp;
  },
  //点击 菜单栏项目 顶部tab
  catalog_item_Tap: function (event) {
    var idx = event.currentTarget.dataset.modelidx;
    this.data.show_catalog_menubar = !this.data.show_catalog_menubar;
    if (this.data.show_catalog_menubar) {
      switch (idx) {
        case "0":
          this.setData({
            current_ca_menu_indi: 0,
          });
          this.setData({
            select_meun_citem_idx: this.data.tag1_select_m_c_idx
          });
          this.data.cata_menucontent_items = this.data.tag1_menucontent_items;
          this.setData({
            cata_menucontent_items: this.data.cata_menucontent_items
          });
          break;
        case "1":
          this.setData({
            current_ca_menu_indi: 1,
          });
          this.setData({
            select_meun_citem_idx: this.data.tag2_select_m_c_idx
          });
          this.data.cata_menucontent_items = this.data.tag2_menucontent_items;
          this.setData({
            cata_menucontent_items: this.data.cata_menucontent_items
          });
          break;
        case "2":
          this.setData({
            current_ca_menu_indi: 2,
          });
          this.setData({
            select_meun_citem_idx: this.data.tag3_select_m_c_idx
          });
          this.data.cata_menucontent_items = this.data.tag3_menucontent_items;
          this.setData({
            cata_menucontent_items: this.data.cata_menucontent_items
          });
          break;
        case "3":
          this.setData({
            current_ca_menu_indi: 3,
          });
          this.setData({
            select_meun_citem_idx: this.data.tag4_select_m_c_idx
          });
          this.data.cata_menucontent_items = this.data.tag4_menucontent_items;
          this.setData({
            cata_menucontent_items: this.data.cata_menucontent_items
          });
          break;
        default:
          console.log("idx not in case");
      }

    }

    var animation = wx.createAnimation({
      duration: 100,
      timingFunction: 'ease',
    })

    this.animation = animation

    animation.translateY(-100).step()

    this.setData({
      animationData: animation.export()
    })

    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 100)
    this.setData({
      show_catalog_menubar: this.data.show_catalog_menubar
    });

  }, shop_item_Tap: function (event) {
    wx.navigateTo({
      url: '../info/info'
    })
  },
  catalog_contentitem_Tap: function (event) {
    var idx = event.currentTarget.dataset.modelidx;
    switch (this.data.current_ca_menu_indi) {
      case 0:
        this.data.tag1_select_m_c_idx = idx;
        break;
      case 1:
        this.data.tag2_select_m_c_idx = idx;
        break;
      case 2:
        this.data.tag3_select_m_c_idx = idx;
        break;
      case 3:
        this.data.tag4_select_m_c_idx = idx;
        break;
      default:
        console.log("idx not in case");
    }
    this.setData({
      select_meun_citem_idx: idx
    });
    this.reload_list_handle();
    console.log("catalog_contentitem_Tap idx is " + idx);
    this.close_topmenu_bar();
  },
  catalog_contentitem_Tap: function (event) {
    var idx = event.currentTarget.dataset.modelidx;
    switch (this.data.current_ca_menu_indi) {
      case 0:
        this.data.tag1_select_m_c_idx = idx;
        break;
      case 1:
        this.data.tag2_select_m_c_idx = idx;
        break;
      case 2:
        this.data.tag3_select_m_c_idx = idx;
        break;
      case 3:
        this.data.tag4_select_m_c_idx = idx;
        break;
      default:
        console.log("idx not in case");
    }
    this.setData({
      select_meun_citem_idx: idx
    });
    this.reload_list_handle();
    console.log("catalog_contentitem_Tap idx is " + idx);
    this.close_topmenu_bar();
  },
  //关闭顶部分类菜单bar
  close_topmenu_bar: function () {
    this.data.show_catalog_menubar = false;
    var animation = wx.createAnimation({
      duration: 100,
      timingFunction: 'ease',
    })
    this.animation = animation
    animation.translateY(-100).step()
    this.setData({
      animationData: animation.export()
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 100)
    this.setData({
      show_catalog_menubar: this.data.show_catalog_menubar
    });
  },
  search_bg_tap: function () {
    // console.log('111');
    wx.redirectTo({
      url: '../search/search'
    })
  },
  onlist_itemTap: function (event) {

    var model = event.currentTarget.dataset.model;
    activityPassParams.setTodetail_model(model);
    wx.navigateTo({
      url: '../chosen/chosen'
    })
  },
})